﻿@model TestOnlineProject.Models.Entities.Participant
@using TestOnlineProject.Models.Entities
@{
    ViewBag.Title = "Create";
}
<script type="text/javascript" language="javascript">
     $(document).ready(function () {
         if($("#UserId").val() ==0) {
             $("#UserId").val('');
         }  
        // Clear userid when section name is changed.
        $("#actual_user").focus(function(){
            switch(complete)
            {
           case true:
            $(this).val('');
                $("#UserId").val('');
                complete = false; 
                break;
            }            
        });        
    });
    // Autpcomplete user.
    var complete = false;
    $(function () {
        $("#actual_user").autocomplete({
            source: "@Url.Content("~/Participant/AutocompleteUser")?id=" + @Model.SubjectId,
            minLength: 1,
            select: function (event, ui) {
                if (ui.item) {
                    $("#actual_user").val(ui.item.value);
                    $("#UserId").val(ui.item.id);
                    $("#actual_user").blur();
                    complete = true;
                }
            } 
        });

    });

</script>
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home") / @Html.ActionLink("Subjects", "Index", "Subject")
    / @Html.ActionLink((ViewBag.Subject as Subject).Code, "Details", "Subject", new { id = (ViewBag.Subject as Subject).SubjectId }, null)
    /
    @Html.ActionLink("Participants", "Index", "Participant", new { subjectId = (ViewBag.Subject as Subject).SubjectId }, null)
    / Create Participant</div>
<br/>
<div class="main_nav">
    <span><a href="@Url.Content("~/Participant/Index")?subjectId=@Model.SubjectId">
        <img src="@Url.Content("~/Images/back button.png")" style="height:30px"/></a>
    </span>
</div>
<br />
<span class="require_info">(*) is required.</span>
@using (Html.BeginForm())
{
    <span class="errorMsg">@Html.ValidationSummary(true)</span>
    <span class="errorMsg">@Html.ValidationMessageFor(model => model.UserId)</span>
    @Html.HiddenFor(model => model.SubjectId)
    @Html.HiddenFor(model => model.UserId)
    <table class="table table-bordered">
        <tr>
            <td style="width: 150px; text-align: right">
                <span>User (*)</span>
            </td>
            <td>
                <input id="actual_user" type="text" class="actual_user" placeholder="Full Name or Username" />
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <button type="submit" class="btn" value="Add" style="width: 80px">
                    Create</button>
                @Html.ActionLink("Reset", "Create", new { subjectId = @ViewBag.Subject.SubjectId }, new { @class = "btn", style = "width: 54px" })
                @Html.ActionLink("Cancel", "Index", new { subjectId = @ViewBag.Subject.SubjectId }, new { @class = "btn", style = "width: 54px" })
            </td>
        </tr>
    </table>
}